package com.yuwei.module_parking.vm

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.entity.AddParkingBody
import com.bw.lib_common.entity.AddParkingEntity
import com.bw.lib_common.entity.ParkingEntity
import com.bw.lib_common.vm.BaseViewModel2
import com.tencent.mmkv.MMKV
import com.yuwei.module_parking.model.ParkingRepository
import kotlinx.coroutines.launch

class ParkingViewModel:BaseViewModel2<ParkingRepository>() {
    //列表
    val  getParkingSuccess by lazy { MutableLiveData<ParkingEntity>() }
    fun ParkingManage(areaId:Int){
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.parkingManage(areaId)
            if (result.code == 200){
                getParkingSuccess.postValue(result.data)
            }
        }
    }
    //添加
    val getAddParkingSuccess by lazy { MutableLiveData<AddParkingEntity>() }
    fun addParkingList(addParkingBody: AddParkingBody){
        mViewModelScope.launch(mDispatcher) {
            val result = mRepository.addParking_list(addParkingBody)
            if (result.code == 200){
                getAddParkingSuccess.postValue(result.data)
            }
        }
    }
//删除
    val  getDeleteParkingSuccess by lazy { MutableLiveData<String>() }
    fun Parking_delete(areaId:Int){
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.parking_delete(areaId)
            if (result.code == 200){
                getDeleteParkingSuccess.postValue(result.data)
            }
        }
    }




    override fun createRepository()=ParkingRepository()


}